package com.hyny.framework.platform.system.sucurity;

import com.alibaba.fastjson.JSONObject;
import com.hyny.framework.platform.system.utils.bean.Result;
import com.hyny.framework.utils.WebUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Configuration
public class CustomLogoutSuccessfulHandler implements LogoutSuccessHandler {

    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {

        // 自定义返回结果
        WebUtil.renderString(httpServletResponse, JSONObject.toJSONString(Result.ok("登出成功")));
    }
}